package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //提莫攻击
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        if(n==1) return duration;
        int count = n*duration;
        for (int i = 1; i < n; i++) {
            if(timeSeries[i]-timeSeries[i-1] < duration)
                count-=duration-(timeSeries[i]-timeSeries[i-1]);
        }
        return count;
    }

    //替换所有的问号
    public String modifyString(String s) {
        char[] ch = s.toCharArray();
        int n = ch.length;
        for (int i = 0; i < n; i++) {
            if(ch[i] == '?') {
                for (char c = 'a'; c <= 'z'; c++) {
                    if ((i == 0 || ch[i - 1] != c) && (i == n - 1 || ch[i + 1] != c)) {
                        ch[i] = c;
                        break;
                    }
                }
            }
        }
        return String.valueOf(ch);
    }
    
    //长度为k的子数组的能量值 2
    public int[] resultsArray(int[] nums, int k) {
        int n = nums.length;
        int[] ret = new int[n+k-1];
        for (int i = 0; i < ret.length; i++) {
            ret[i] = -1;
        }
        int count = 0;
        for(int i=0;i<n;i++){
            count= i == 0 || nums[i] - nums[i - 1] != 1 ? 1 : count + 1;
            if (count >= k) {
                ret[i+k-1] = nums[i];
            }
        }
        return ret;
    }
}
